<html>
<head><meta charset="utf-8"><title>error: cannot find a built-in macro with name `cfg` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html">error: cannot find a built-in macro with name `cfg`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206377153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/error%3A%20cannot%20find%20a%20built-in%20macro%20with%20name%20%60cfg%60/near/206377153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html#206377153">(Aug 09 2020 at 03:51)</a>:</h4>
<p>Copying from <a href="https://github.com/rust-lang/rust/pull/75176#issuecomment-671001837">https://github.com/rust-lang/rust/pull/75176#issuecomment-671001837</a> for convenience:</p>
<p>The error comes from here: <a href="https://github.com/rust-lang/rust/blob/e539dd65f8ba80837f7477c0547c61514bceb3ad/src/librustc_resolve/macros.rs#L1077-L1087">https://github.com/rust-lang/rust/blob/e539dd65f8ba80837f7477c0547c61514bceb3ad/src/librustc_resolve/macros.rs#L1077-L1087</a></p>
<p>Note that <code>compile_macro</code> uses <code>builtin_macros.remove</code> instead of <code>.get</code>. So I think it expects to only ever be called once. I'm not sure <em>why</em> it was called more than once - I'd expect it to only be called once during <code>expand</code>.</p>
<p>There are a bunch of other questions that pop up, like</p>
<ul>
<li>Why does this only happen when documenting <code>proc_macro</code>?</li>
<li>How is this possibly affected by my change?</li>
</ul>



<a name="206425868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/error%3A%20cannot%20find%20a%20built-in%20macro%20with%20name%20%60cfg%60/near/206425868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html#206425868">(Aug 10 2020 at 03:54)</a>:</h4>
<p>I think this might be because rustdoc is generating fake DefIds - this panics when you try to print the def id:</p>
<div class="codehilite"><pre><span></span><code>thread &#39;rustc&#39; panicked at &#39;index out of bounds: the len is 18 but the index is 18&#39;, src/librustc_metadata/creader.rs:128:21
</code></pre></div>


<p>cc <span class="user-mention" data-user-id="119009">@eddyb</span> - rustc_metadata is your specialty and also <code>git blame</code> shows you as the last one to touch <code>next_def_id</code> on <code>auto_trait</code> and <code>blanket_impls</code>. Do you know how <code>rustc_resolve</code> could possibly be seeing a fake ID created by rustdoc?</p>



<a name="206425871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/error%3A%20cannot%20find%20a%20built-in%20macro%20with%20name%20%60cfg%60/near/206425871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html#206425871">(Aug 10 2020 at 03:54)</a>:</h4>
<p>(more info on the PR)</p>



<a name="206425893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/error%3A%20cannot%20find%20a%20built-in%20macro%20with%20name%20%60cfg%60/near/206425893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html#206425893">(Aug 10 2020 at 03:55)</a>:</h4>
<p>and also, why does rustdoc create fake IDs in the first place instead of using <code>param_env_def_id</code> and <code>impl_def_id</code>?</p>



<a name="206426000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/error%3A%20cannot%20find%20a%20built-in%20macro%20with%20name%20%60cfg%60/near/206426000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/error.3A.20cannot.20find.20a.20built-in.20macro.20with.20name.20.60cfg.60.html#206426000">(Aug 10 2020 at 03:57)</a>:</h4>
<p>ugh this didn't fix it</p>
<div class="codehilite"><pre><span></span><code><span class="gh">diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs</span>
<span class="gh">index 9c44d27447d..0325ea75445 100644</span>
<span class="gd">--- a/src/librustdoc/clean/auto_trait.rs</span>
<span class="gi">+++ b/src/librustdoc/clean/auto_trait.rs</span>
<span class="gu">@@ -122,7 +122,8 @@ impl&lt;&#39;a, &#39;tcx&gt; AutoTraitFinder&lt;&#39;a, &#39;tcx&gt; {</span>
                     name: None,
                     attrs: Default::default(),
                     visibility: Inherited,
<span class="gd">-                    def_id: self.cx.next_def_id(param_env_def_id.krate),</span>
<span class="gi">+                    //def_id: self.cx.next_def_id(param_env_def_id.krate),</span>
<span class="gi">+                    def_id: param_env_def_id,</span>
                     stability: None,
                     deprecation: None,
                     inner: ImplItem(Impl {
<span class="gh">diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl</span>
.rs
<span class="gh">index 3d2785541be..d3f87c91279 100644</span>
<span class="gd">--- a/src/librustdoc/clean/blanket_impl.rs</span>
<span class="gi">+++ b/src/librustdoc/clean/blanket_impl.rs</span>
<span class="gu">@@ -96,7 +96,8 @@ impl&lt;&#39;a, &#39;tcx&gt; BlanketImplFinder&lt;&#39;a, &#39;tcx&gt; {</span>
                     name: None,
                     attrs: Default::default(),
                     visibility: Inherited,
<span class="gd">-                    def_id: self.cx.next_def_id(impl_def_id.krate),</span>
<span class="gi">+                    //def_id: self.cx.next_def_id(impl_def_id.krate),</span>
<span class="gi">+                    def_id: impl_def_id,</span>
                     stability: None,
                     deprecation: None,
                     inner: ImplItem(Impl {
</code></pre></div>


<p>so maybe fake IDs aren't to blame after all? I don't see <code>next_def_id</code> used anywhere else</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>